from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-12 14:11:17.610430
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 12, Apr, 2021
Time: 14:11:21
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4737
Nobs: 259.000 HQIC: -48.2127
Log likelihood: 3090.35 FPE: 7.01170e-22
AIC: -48.7096 Det(Omega_mle): 4.98598e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.448414 0.124645 3.598 0.000
L1.Burgenland 0.068526 0.061842 1.108 0.268
L1.Kärnten -0.223067 0.053746 -4.150 0.000
L1.Niederösterreich 0.056950 0.133747 0.426 0.670
L1.Oberösterreich 0.222827 0.126474 1.762 0.078
L1.Salzburg 0.272380 0.069892 3.897 0.000
L1.Steiermark 0.131157 0.089207 1.470 0.141
L1.Tirol 0.122512 0.061231 2.001 0.045
L1.Vorarlberg -0.031513 0.056561 -0.557 0.577
L1.Wien -0.055980 0.115504 -0.485 0.628
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.490775 0.147037 3.338 0.001
L1.Burgenland -0.004214 0.072952 -0.058 0.954
L1.Kärnten 0.329502 0.063401 5.197 0.000
L1.Niederösterreich 0.076640 0.157774 0.486 0.627
L1.Oberösterreich -0.061693 0.149194 -0.414 0.679
L1.Salzburg 0.221100 0.082448 2.682 0.007
L1.Steiermark 0.109368 0.105232 1.039 0.299
L1.Tirol 0.143067 0.072230 1.981 0.048
L1.Vorarlberg 0.155047 0.066722 2.324 0.020
L1.Wien -0.446788 0.136254 -3.279 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290261 0.062905 4.614 0.000
L1.Burgenland 0.091560 0.031210 2.934 0.003
L1.Kärnten -0.017527 0.027124 -0.646 0.518
L1.Niederösterreich 0.059552 0.067498 0.882 0.378
L1.Oberösterreich 0.275463 0.063828 4.316 0.000
L1.Salzburg 0.024287 0.035273 0.689 0.491
L1.Steiermark 0.010321 0.045020 0.229 0.819
L1.Tirol 0.073019 0.030901 2.363 0.018
L1.Vorarlberg 0.081905 0.028545 2.869 0.004
L1.Wien 0.115586 0.058292 1.983 0.047
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217953 0.061561 3.540 0.000
L1.Burgenland 0.021440 0.030543 0.702 0.483
L1.Kärnten 0.009051 0.026544 0.341 0.733
L1.Niederösterreich 0.050724 0.066056 0.768 0.443
L1.Oberösterreich 0.401672 0.062464 6.430 0.000
L1.Salzburg 0.082734 0.034519 2.397 0.017
L1.Steiermark 0.130248 0.044058 2.956 0.003
L1.Tirol 0.050184 0.030241 1.659 0.097
L1.Vorarlberg 0.084039 0.027935 3.008 0.003
L1.Wien -0.047946 0.057046 -0.840 0.401
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.503515 0.120225 4.188 0.000
L1.Burgenland 0.088418 0.059649 1.482 0.138
L1.Kärnten 0.011274 0.051840 0.217 0.828
L1.Niederösterreich -0.000818 0.129005 -0.006 0.995
L1.Oberösterreich 0.132605 0.121990 1.087 0.277
L1.Salzburg 0.059189 0.067414 0.878 0.380
L1.Steiermark 0.068326 0.086044 0.794 0.427
L1.Tirol 0.213648 0.059060 3.617 0.000
L1.Vorarlberg 0.030941 0.054556 0.567 0.571
L1.Wien -0.099246 0.111409 -0.891 0.373
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186089 0.095026 1.958 0.050
L1.Burgenland -0.013116 0.047146 -0.278 0.781
L1.Kärnten -0.008476 0.040974 -0.207 0.836
L1.Niederösterreich -0.006994 0.101964 -0.069 0.945
L1.Oberösterreich 0.400565 0.096420 4.154 0.000
L1.Salzburg 0.017588 0.053283 0.330 0.741
L1.Steiermark -0.017611 0.068009 -0.259 0.796
L1.Tirol 0.159404 0.046680 3.415 0.001
L1.Vorarlberg 0.051877 0.043121 1.203 0.229
L1.Wien 0.235520 0.088057 2.675 0.007
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.241017 0.115761 2.082 0.037
L1.Burgenland 0.019144 0.057434 0.333 0.739
L1.Kärnten -0.068649 0.049915 -1.375 0.169
L1.Niederösterreich -0.070272 0.124214 -0.566 0.572
L1.Oberösterreich 0.020058 0.117459 0.171 0.864
L1.Salzburg 0.082316 0.064910 1.268 0.205
L1.Steiermark 0.335808 0.082848 4.053 0.000
L1.Tirol 0.461890 0.056866 8.122 0.000
L1.Vorarlberg 0.147598 0.052530 2.810 0.005
L1.Wien -0.164540 0.107271 -1.534 0.125
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173572 0.137607 1.261 0.207
L1.Burgenland 0.038037 0.068273 0.557 0.577
L1.Kärnten -0.077205 0.059335 -1.301 0.193
L1.Niederösterreich 0.118432 0.147655 0.802 0.423
L1.Oberösterreich 0.021480 0.139626 0.154 0.878
L1.Salzburg 0.204081 0.077160 2.645 0.008
L1.Steiermark 0.121355 0.098484 1.232 0.218
L1.Tirol 0.057462 0.067598 0.850 0.395
L1.Vorarlberg 0.102864 0.062443 1.647 0.099
L1.Wien 0.245960 0.127516 1.929 0.054
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.570832 0.074497 7.662 0.000
L1.Burgenland -0.033814 0.036961 -0.915 0.360
L1.Kärnten -0.022865 0.032122 -0.712 0.477
L1.Niederösterreich 0.045576 0.079937 0.570 0.569
L1.Oberösterreich 0.315665 0.075590 4.176 0.000
L1.Salzburg 0.021044 0.041773 0.504 0.614
L1.Steiermark -0.034270 0.053317 -0.643 0.520
L1.Tirol 0.086767 0.036596 2.371 0.018
L1.Vorarlberg 0.108371 0.033805 3.206 0.001
L1.Wien -0.050366 0.069034 -0.730 0.466
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.145846 0.075268 0.164636 0.221091 0.079412 0.083664 0.006823 0.152432
Kärnten 0.145846 1.000000 0.035319 0.202798 0.178278 -0.061291 0.163560 0.027610 0.302974
Niederösterreich 0.075268 0.035319 1.000000 0.238752 0.076038 0.325583 0.141633 0.027628 0.293903
Oberösterreich 0.164636 0.202798 0.238752 1.000000 0.300549 0.268208 0.088981 0.059379 0.134471
Salzburg 0.221091 0.178278 0.076038 0.300549 1.000000 0.154448 0.052962 0.087871 0.005282
Steiermark 0.079412 -0.061291 0.325583 0.268208 0.154448 1.000000 0.104253 0.093664 -0.106500
Tirol 0.083664 0.163560 0.141633 0.088981 0.052962 0.104253 1.000000 0.162760 0.146387
Vorarlberg 0.006823 0.027610 0.027628 0.059379 0.087871 0.093664 0.162760 1.000000 -0.005224
Wien 0.152432 0.302974 0.293903 0.134471 0.005282 -0.106500 0.146387 -0.005224 1.000000